using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel.Design;
using System.Text;
using GuavaData;
using System.ComponentModel.Design.Serialization;
using System.CodeDom;

namespace GuavaLib
{
    public partial class GLookupTable : GComponentBase
    {
        string tableName;
        List<GLookupTableColumn> columns = new List<GLookupTableColumn>();

        public GLookupTable()
        {
            InitializeComponent();
        }
        
        public GLookupTable(IContainer container)
        {
            container.Add(this);
            InitializeComponent();
        }

        #region Guava Members

        [Browsable(false)]
        public override LaunchType LType
        {
            get { return LaunchType.NA; }
        }

        [Browsable(false)]
        public override ControlType CType
        {
            get { return ControlType.Extern; }
        }

        [Browsable(false)]
        public override string GText
        {
            get { return "External Lookup Table Column"; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override string GName
        {
            get
            {
                return this.tableName;
            }
            set
            {
                this.tableName = value;
            }
        }

        [Browsable(false)]
        public override List<Guava> GComponents
        {
            get
            {
                List<Guava> lg = new List<Guava>();
                foreach (GLookupTableColumn glc in this.columns) lg.Add(glc);
                return lg;
            }
        }

        public override void GBind(string table, int i)
        {
            return;
        }

        [Browsable(false)]
        public override GuavaData.Domain.Domain GDomain
        {
            get { return new GuavaData.Domain.UniqueIdentifier(); }
        }

        #endregion

        [DefaultValue(null)]
        public string TableName
        {
            get { return tableName; }
            set { tableName = value; }
        }

        public GLookupTableColumn[] Columns
        {
            get
            {
                if (columns == null) return new GLookupTableColumn[0];
                return columns.ToArray();
            }
            set
            {
                if (columns == null) columns = new List<GLookupTableColumn>();
                else columns.Clear();
                columns.AddRange(value);
            }
        }
    }
}
